package com.dhcc.sds.base.controller;


import java.util.List;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;



import com.dhcc.sds.base.entity.SdsValItemEntity;
import com.dhcc.sds.base.service.ISdsValItemService;


/**
 * 病种项目评分项表
 * 
 * @ClassName: SdsValItemController
 * @Description: TODO
 * @author sunyingjie
 * @date 2021-04-15 11:14:53
 */
@Controller
@RequestMapping("${sys.backendPath}/sds/sdsvalitem")
public class SdsValItemController extends BaseController {

	private String PREFIX = "/backend/sds/sdsvalitem/";

	@Autowired
	private ISdsValItemService sdsValItemService;
	

    /**
     * 跳转到病种项目评分项表列表首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "sdsvalitem.html";
    }
	
    /**
     * 跳转到新增病种项目评分项表
     */
    @RequestMapping("/to_add")
    public String toAdd() {
        return PREFIX + "sdsvalitem_add.html";
    }
	
	/**
     * 跳转到修改病种项目评分项表
     */
    @RequestMapping("/to_update/{sdsValItemId}")
    public String toUpdate(@PathVariable Long sdsValItemId, Model model) {
        SdsValItemEntity sdsValItem = this.sdsValItemService.selectById(sdsValItemId);
        model.addAttribute("sdsValItem",sdsValItem);
        return PREFIX + "sdsvalitem_edit.html";
    }

    /**
     * 获取病种项目评分项表列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam Map<String, Object> params) {
		Page<SdsValItemEntity> page = new PageFactory<SdsValItemEntity>().defaultPage();
        List<SdsValItemEntity> result = this.sdsValItemService.page(page,params);
        page.setRecords((List<SdsValItemEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增病种项目评分项表
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(SdsValItemEntity sdsValItem) {
        if (CommonUtil.isOneEmpty(sdsValItem)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        sdsValItem.insert();
        return R.ok();
    }

    /**
     * 删除病种项目评分项表
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long sdsValItemId) {
	
        this.sdsValItemService.deleteById(sdsValItemId);

        return R.ok();
    }

    /**
     * 修改病种项目评分项表
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(SdsValItemEntity sdsValItem) {
        if (CommonUtil.isOneEmpty(sdsValItem)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        SdsValItemEntity old = this.sdsValItemService.selectById(sdsValItem.getId());

        old.setFormItemId(sdsValItem.getFormItemId());
        old.setCode(sdsValItem.getCode());
        old.setDesc(sdsValItem.getDesc());
        old.setIndNo(sdsValItem.getIndNo());
        old.setIsActive(sdsValItem.getIsActive());
        old.setUpdateUser(sdsValItem.getUpdateUser());
        old.updateAllColumnById();
        return R.ok();
    }
	
}
